root = File.dirname(__FILE__)+'/../'

require 'logger'

# TODO cleanup
#construct the DM app
app = DrunkenMaster::HtmlApplication.new()
app.router.plug Documentation::Application, '/'
dm_app = DrunkenMaster::RackAdapter.new(app)

#build the app using middleware
rack_app = Rack::Builder.new {

  #show exceptions only in non production mode
  if DrunkenMaster::ENV != 'production'
    use Rack::ShowExceptions
  end

  # log to file
  use Rack::CommonLogger, Logger.new(root+"/log/#{DrunkenMaster::ENV}.log")

  #log to stdout for netbeans
  use Rack::CommonLogger, Logger.new(STDOUT)

  #map the app to the root
  map "/" do
    #use Rack::Lint
    run dm_app
  end
}

#add session pool middleware
sessioned_app = Rack::Session::Pool.new(rack_app,
  :key => 'dm.session',
  #:domain => '127.0.0.1', # if you want to force the domain
  :path => '/',
  :expire_after => 1*24*60*60
)

DrunkenMaster::App = sessioned_app
